home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Programmer's Power Pack
/
Delphi Volume 1.iso
/
e_to_l
/
fbuilder
/
delphi
/
demos
/
newvarfm.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-09-15
|
2KB
|
90 lines
{ FormulaBuilder }
{ YGB Software, Inc. }
{ Copyright 1995 Clayton Collie }
{ All rights reserved }
{* Form to allow the addition of a variable to an expression *}
{* uses DLL level calls via the expression handle *}
unit Newvarfm;
interface
uses
FBcalc,
WinTypes, WinProcs, Classes, Graphics, Forms, Controls, Buttons,
StdCtrls, ExtCtrls;
type
TNewVariableDlg = class(TForm)
OKBtn: TBitBtn;
CancelBtn: TBitBtn;
VarnameEdit: TEdit;
RadioGroup1: TRadioGroup;
Bevel1: TBevel;
Label1: TLabel;
procedure OKBtnClick(Sender: TObject);
private
{ Private declarations }
fHandle : HEXPR;
public
{ Public declarations }
end;
var
NewVariableDlg: TNewVariableDlg;
Function AddNewVariable(handle : HEXPR):boolean;
implementation
uses sysutils;
{$R *.DFM}
Function AddNewVariable(handle : HEXPR):boolean;
var fm : TNewVariableDlg;
begin
Application.CreateForm(TNewVariableDlg,fm);
InitFbuilder; { just to ensure DLL is loaded }
TRY
Fm.fHandle := handle;
result := (fm.Showmodal = mrOk);
FINALLY
fm.free;
FreeFBuilder; { To match InitFBuilder }
END;
end;
procedure TNewVariableDlg.OKBtnClick(Sender: TObject);
var ident : string[60];
tmp : string[60];
vtype : integer;
val : array[0..10] of byte;
res : pchar;
begin
ident := VarnameEdit.Text;
tmp := ident + #0;
if not isValidIdent(Ident) then
begin
Application.MessageBox('Invalid variable name ',
'Definition Error',MB_OK or MB_ICONHAND);
exit;
end;
res := @val;
if FBGetVarAsString(fHandle,@tmp[1],res,sizeof(val)-1) = EXPR_SUCCESS then
begin
Application.MessageBox('The variable already exists ',
'Definition Error',MB_OK or MB_ICONHAND);
exit;
end;
res := @tmp[1];
Case RadioGroup1.ItemIndex of
0 : FBAddVariable(fhandle,Res, vtInteger ); { vtInteger; }
1 : FBAddVariable(fhandle,Res, vtFloat ); { vtFloat; }
2 : FBAddVariable(fHandle,Res, vtBoolean ); { vtBoolean;}
3 : FbAddVariable(fHandle,Res, vtString ); { vtString; }
4 : FBAddVariable(fhandle,Res, vtDate ); { vtDate; }
end;
end;
end.